﻿using System;
using System.Linq;
using System.Text;
using System.Data;
using System.Collections.Generic;
using System.Data.SqlServerCe;

namespace DiabetesMonitor
{
    class Utilities
    {
        #region Get DB Connection String 
        public static string GetDBConnectionString()
        {
            return "Data Source=" + System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase) + @"\Records.sdf";
        }
        #endregion 

        #region Resize Array
        public static System.Array ResizeArray(System.Array oldArray, int newSize)
        {
            int oldSize = oldArray.Length;
            System.Type elementType = oldArray.GetType().GetElementType();
            System.Array newArray = System.Array.CreateInstance(elementType, newSize);
            int preserveLength = System.Math.Min(oldSize, newSize);
            if (preserveLength > 0)
                System.Array.Copy(oldArray, newArray, preserveLength);
            return newArray;
        }
        #endregion

        #region *****Old Store Local code 
        //public bool StoreLocal(DiabetesMonitor.Item i)
        //{
        //    using (SqlCeConnection hConn = new SqlCeConnection(Utilities.GetDBConnectionString()))
        //    {
        //        hConn.Open();
        //        string sSQL = "";

        //        if (i.id <= 0)
        //        {        //New object, insert to db
        //            sSQL = "INSERT INTO tblRecords (id, InsulinLevel, SugarLevel, TimeOfDay, Medication) VALUES ('" +
        //                Convert.ToInt32(i.id) + "', '" + i.InsulinLevel + "', '" + i.SugarLevel + "', '" + i.TimeOfDay + "', '" + i.Medication + "')";
        //            SqlCeCommand oCommand = new SqlCeCommand(sSQL, hConn);
        //            oCommand.ExecuteNonQuery();

        //            hConn.Close();

        //            return true;
        //        }
        //    }
        //    return false;
        //}
        #endregion


    }
}